export const useCount = {
  props: {
    range: {
      type: Object,
      default: () => {
        return {
          min: 1,
          max: 20
        }
      }
    },
  },
  data() {
    return {
      current: 0
    }
  },
  created: function () {
    // this.hello()
  },
  methods: {
    minus: (num) => {
      this.current -= num;
    },
    plus: (num) => {
      this.current += num;
    },
    set: (num) => {
      this.current = num;
    },
    reset: (init) => {
      this.current = init;
    }
  },
  watch: {
    'current': {
      handler: function (newVal, oldVal) {
        console.log(newVal, oldVal);
        if (newVal === oldVal) return;
        if (newVal < +this.range.min) {
          this.current = +this.range.min;
        } else if (newVal > +this.range.max) {
          this.current = +this.range.max;
        }
      }
    }
  }
}